package com.karson.common.request;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.Data;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author ZKS
 */
@Data
public class CommentRequest {
    @JsonProperty("aId")
    private Integer aId;
    private Integer rootId;
    private String message;
    private Integer parentId;
    private List<String> pictures;
    private Map<String, Integer> atNameToMid;
    private Map<String, Integer> jumpToAid;

    public String buildContentJson() throws JsonProcessingException {
        ObjectMapper objectMapper = new ObjectMapper();
        Map<String, Object> content = new HashMap<>(4);

        if (message != null && !message.isEmpty()) {
            content.put("message", message);
        }
        if (pictures != null && !pictures.isEmpty()) {
            content.put("pictures", pictures);
        }
        if (atNameToMid != null && !atNameToMid.isEmpty()) {
            content.put("atNameToMid", atNameToMid);
        }
        if (jumpToAid != null && !jumpToAid.isEmpty()) {
            content.put("jumpToAid", jumpToAid);
        }

        return objectMapper.writeValueAsString(content);
    }
}
